use crate::error::{AppError, Result};
use duckdb::Connection;
use std::path::PathBuf;
use crate::common::variables::get_project_base_dir;

static DUCKDB_NAME: &str = "analysis.db";

pub fn get_connection() -> Result<Connection> {
    let base_dir =  get_project_base_dir();
    if base_dir == "" { return Err(AppError::Custom("项目还没有初始化！".into())) }
    // 将字符串转换为PathBuf
    let base_path = PathBuf::from(base_dir);
    // 拼接路径
    let db_path = base_path.join(DUCKDB_NAME);
    // 创建链接
    let conn = Connection::open(db_path)?;
    Ok(conn)
}

